import { ENUM_CLIP, ENUM_UI } from "../GbzEnum";
import GbzInstance from "../GbzInstance";
import GbzAudioManager from "../manager/GbzAudioManager";
import GbzSdkManager from "../manager/GbzSdkManager";
import GbzToastManager from "../manager/GbzToastManager";
import BaseLayer from "./GbzBaselayer";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GbzMenuLayer extends BaseLayer {

    btn_start: cc.Node = null
    // btn_rank: cc.Node = null
    btn_setting: cc.Node = null
    // btn_share: cc.Node = null
    btn_more: cc.Node = null
    btn_silder:cc.Node = null

    onLoad() {
        
        this.btn_start = cc.find('main/btn_start', this.node)
        this.btn_start.on('click', this.onStart, this)
        // this.btn_rank = cc.find('main/btn_rank', this.node)
        // this.btn_rank.on('click', this.onRank, this)
        this.btn_setting = cc.find('btn_setting', this.node)
        this.btn_setting.on('click', this.onSetting, this)
        // this.btn_share = cc.find('left/btn_share', this.node)
        // this.btn_share.on('click', this.onShare, this)
        this.btn_more = cc.find('left/btn_more', this.node)
        this.btn_more.on('click', this.onMore, this)
        
    }

    onDestroy() {
        this.btn_start.off('click', this.onStart, this)
        // this.btn_rank.off('click', this.onRank, this)
        this.btn_setting.off('click', this.onSetting, this)
        // this.btn_share.off('click', this.onShare, this)
        this.btn_more.off('click', this.onMore, this)
    }

    async onStart() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        await GbzInstance.fadeMgr.in()
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_MENU, false)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_MAIN)
        GbzInstance.gameMgr.onGameStart()
    }

    onRank() {
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_RANK)
    }

    onSetting() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_MENU, false)
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_SETTING)
    }

    onShare() {
        GbzAudioManager.ins.play(ENUM_CLIP.GAME_CLICK)
        if (GbzSdkManager.ins.platform()) {
            GbzSdkManager.ins.activeShare()
        } else {
            GbzToastManager.ins.show('仅支持小游戏平台', { gravity: 'TOP', bg_color: cc.color(102, 202, 28, 255) })
        }
    }
    // 去侧边栏
    onMore() {
        GbzInstance.uiMgr.toggle(ENUM_UI.LAYER_RANK)
    }
}
